/*
 * SignalData.cpp
 *
 *  Created on: Jul 13, 2009
 *      Author: zaca
 */

#include "signaldata.h"
#include <iostream>

namespace biosignal
{

using namespace std;

SignalData::SignalData(const SourceSignal* signal_info) : m_signal_info(signal_info)
{
//	cout << "creating SignalData : "  << endl;
}
SignalData::~SignalData()
{
//	cout << "deleting SignalData : "  << endl;
}

const SourceSignal* SignalData::signal_info() const
{
	return m_signal_info;
}
DataIterator SignalData::begin() const
{
	DataIterator begin(this, 0);
	return begin;
}
DataIterator SignalData::end() const
{
	DataIterator end(this, -1);
	return end;
}

DataIterator::DataIterator(const SignalData* signal_data, long current_id) :
	m_signal_data(signal_data), m_current_id(current_id)
{
//		cout << "--- data iterator " << m_current_id << " signal data  : " << m_signal_data << endl;

}
bool DataIterator::operator==(const DataIterator & other) const
{
	//	cout << "operator== " << m_current_id << "  other.operator " << other.m_current_id << endl;
	return (m_current_id == other.m_current_id);
}
bool DataIterator::operator!=(const DataIterator& other) const
{
	//	cout << "operator!= " << m_current_id << "  other.operator " << other.m_current_id << endl;
	bool result = (m_current_id >= 0) ? (m_current_id != other.m_current_id)
			: false;
	//	cout << "operator!= " << result << endl;
	return result;
}
double DataIterator::operator*() const
{
//	cout << "--- start operator* " << m_current_id  << endl;
//	cout << "--- m_signal_data : " << m_signal_data  << endl;
	double val = m_signal_data->value(m_current_id);
//	cout << "--- val : " << val  << endl;
	return val;
}
DataIterator& DataIterator::operator++()
{
	//		cout << "--- start operator++ " << m_current_id  << endl;
	if (m_current_id >= 0 && m_current_id < m_signal_data->size()-1)
	{
		m_current_id++;
	}
	else
	{
		m_current_id = -1;
	}
	//		cout << "--- end operator++ " << m_current_id  << endl;
	return *this;
}

DataIterator& DataIterator::operator--()
{
	//		cout << "--- start operator++ " << m_current_id  << endl;
	if (m_current_id >= 0 && m_current_id < m_signal_data->size()-1)
	{
		m_current_id--;
	}
	else
	{
		m_current_id = -1;
	}
	//		cout << "--- end operator++ " << m_current_id  << endl;
	return *this;
}

DataIterator DataIterator::operator++(int)
{
	DataIterator result(*this);
	++(*this);
	return (result);
}

}
